<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" :width="700" :canFullscreen="false">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, computed, unref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { formSchema1 } from './protocol.data';

  // 声明Emits
  const emit = defineEmits(['register']);
  const isUpdate = ref(true);
  //表单配置
  const [registerForm, { resetFields, setFieldsValue, setProps }] = useForm({
    baseColProps: {
      span: 12,
    },
    wrapperCol: {
      md: { span: 20 },
      sm: { span: 18 },
    },
    labelWidth: 120,
    layout: 'vertical',
    schemas: formSchema1,
    showActionButtonGroup: false,
  });
  //表单赋值
  const [registerModal, { setModalProps }] = useModalInner(async (data) => {
    //重置表单
    await resetFields();
    isUpdate.value = !!data?.isUpdate;
    if (unref(isUpdate)) {
      //表单赋值
      await setFieldsValue({
        ...data.record,
      });
    }
    setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
    setProps({ disabled: !data?.showFooter });
  });
  //设置标题
  const getTitle = computed(() => '协议详情');
</script>
